/**
 * 
 */
package com.dsteiner.xelavos.client;



import com.dsteiner.widgets.client.DateUtilImpl;
import com.dsteiner.widgets.client.JsUtil;
import com.dsteiner.widgets.client.PrefilledDateBox;
import com.dsteiner.widgets.client.PrefilledRichTextArea;
import com.dsteiner.widgets.client.PrefilledTextArea;
import com.dsteiner.widgets.client.PrefilledTextBox;
import com.dsteiner.widgets.client.SuggestBoxWidget;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.model.PrefilledTextBoxModel;
import com.dsteiner.widgets.client.model.SuggestBoxModel;
import com.dsteiner.xelavos.client.constants.Constants;
import com.dsteiner.xelavos.client.controller.CreateProductController;
import com.dsteiner.xelavos.client.model.CreateObjectModel;
import com.dsteiner.xelavos.client.model.MainTabModel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.datepicker.client.DatePicker;

public class CreateProductWidget extends LazyWidget {

	private final CreateProductController createProductController;
	private final CreateObjectModel createObjectModel;
	private final MainTabModel mainTabModel;

	public CreateProductWidget(CreateProductController createProductController, 
			CreateObjectModel createObjectModel, MainTabModel mainTabModel) {
		this.createProductController = createProductController;
		this.createObjectModel = createObjectModel;
		this.mainTabModel = mainTabModel;
	}
	
	@Override
	public Widget createContentWidget() {
		FlowPanelExt flowPanel = new FlowPanelExt();
		SuggestBoxModel nameTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget nameTextBox = new SuggestBoxWidget(nameTextBoxModel, new SelectedTabSuggestBoxDataProvider(mainTabModel));
		nameTextBoxModel.setDefaultText("<span class=\"main\">nombre</span> <span class=\"requiredField\">*</span> (ej Televisor)");
		PrefilledTextBoxModel modelTextBoxModel = new PrefilledTextBoxModel();
		modelTextBoxModel.setDefaultText("<span class=\"main\">modelo</span> (ej OHC-1492)");
		PrefilledTextBox modelTextBox = new PrefilledTextBox(modelTextBoxModel);
		SuggestBoxModel brandTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget brandTextBox = new SuggestBoxWidget(brandTextBoxModel, new SelectedTabSuggestBoxDataProvider(mainTabModel));
		brandTextBoxModel.setDefaultText("<span class=\"main\">marca</span> (ej Sony)");
		PrefilledTextBoxModel priceTextBoxModel = new PrefilledTextBoxModel();
		priceTextBoxModel.setDefaultText("<span class=\"main\">precio</span> (ej 19.99)");
		PrefilledTextBox priceTextBox = new PrefilledTextBox(priceTextBoxModel);
		PrefilledTextBoxModel descriptionTextBoxModel = new PrefilledTextBoxModel();
		descriptionTextBoxModel.setDefaultText("<span class=\"main\">detalles</span> (ej 14'' pantalla convencional)");
		PrefilledRichTextArea descriptionTextBox = new PrefilledRichTextArea(descriptionTextBoxModel);
		PrefilledTextBoxModel validUntilTextBoxModel = new PrefilledTextBoxModel();
		validUntilTextBoxModel.setDefaultText("<span class=\"main\">valido hasta</span> (ej 24/12/2009)");
		DatePicker datePicker = new DatePicker();
		PrefilledDateBox validUntilDateTextBox = new PrefilledDateBox(validUntilTextBoxModel, datePicker, DateUtilImpl.formatterSpanish);
		PrefilledTextBoxModel contactTextBoxModel = new PrefilledTextBoxModel();
		contactTextBoxModel.setDefaultText("<span class=\"main\">contacto</span> (ej direccion y/o email y/o telefono)");
		PrefilledTextArea contactTextBox = new PrefilledTextArea(contactTextBoxModel);
		SuggestBoxModel shopTextBoxModel = new SuggestBoxModel();
		SuggestBoxWidget shopTextBox = new SuggestBoxWidget(shopTextBoxModel, new SelectedTabSuggestBoxDataProvider(mainTabModel));
		shopTextBoxModel.setDefaultText("<span class=\"main\">tienda</span> (ej Hiper Paiz)");
		
		contactTextBoxModel.setMaxCount(Constants.MAX_COUNT_STRING);
		
		flowPanel.add((Widget)nameTextBox);
		flowPanel.add((Widget)priceTextBox);
		flowPanel.add((Widget)shopTextBox);
		flowPanel.add((Widget)brandTextBox);
		flowPanel.add((Widget)modelTextBox);
		flowPanel.add((Widget)validUntilDateTextBox);
		flowPanel.add((Widget)contactTextBox);
		flowPanel.add((Widget)descriptionTextBox);
		
		nameTextBox.setTabIndex(92);
		priceTextBox.setTabIndex(93);
		shopTextBox.setTabIndex(94);
		brandTextBox.setTabIndex(95);
		modelTextBox.setTabIndex(96);
		validUntilDateTextBox.setTabIndex(97);
		contactTextBox.setTabIndex(98);
		descriptionTextBox.setTabIndex(99);
		
		nameTextBox.getElement().getStyle().setZIndex(10);
		priceTextBox.getElement().getStyle().setZIndex(9);
		shopTextBox.getElement().getStyle().setZIndex(8);
		brandTextBox.getElement().getStyle().setZIndex(7);
		modelTextBox.getElement().getStyle().setZIndex(6);
		validUntilDateTextBox.getElement().getStyle().setZIndex(5);
		contactTextBox.getElement().getStyle().setZIndex(4);
		descriptionTextBox.getElement().getStyle().setZIndex(3);

		createProductController.registerJsUtil(JsUtil.getInstance());
		createProductController.registerNameTextBoxModel(nameTextBoxModel);
		createProductController.registerPriceTextBoxModel(priceTextBoxModel);
		createProductController.registerModelTextBoxModel(modelTextBoxModel);
		createProductController.registerBrandTextBoxModel(brandTextBoxModel);
		createProductController.registerValidUntilTextBoxModel(validUntilTextBoxModel);
		createProductController.registerShopTextBoxModel(shopTextBoxModel);
		createProductController.registerContactTextBoxModel(contactTextBoxModel);
		createProductController.registerDescriptionTextBoxModel(descriptionTextBoxModel);
		createProductController.registerCreateObjectWidget(this);
		createProductController.registerCreateObjectModel(createObjectModel);
		return flowPanel;
	}
}